home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-20 | 4.2 KB | 172 lines | [TEXT/CWIE] |
- #include "ocheaders.h"
- #include "BDDISPIDs.h"
- #include "CBaseControl.h"
- #include "CBaseEventServer.h"
- #include "BDUtils.h"
- #include "BDAssert.h"
- #include "FnAssert.h"
- #include "dispatch.h"
- #include <LArray.h>
- #include <LArrayIterator.h>
- #include "CConnectionPoint.h"
- #include "CCPContainer.h"
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // Constants
- //
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // class statics
- //
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CBaseEventServer::CBaseEventServer
- //
- CBaseEventServer::CBaseEventServer(void)
- {
- mOutgoingInterfaceID = kUninitializedInterfaceID;
- mCPContainerObj = NULL;
- mCPContainerP = NULL;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CBaseEventServer::~CBaseEventServer
- //
- CBaseEventServer::~CBaseEventServer()
- {
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CBaseControl::IUnknown::QueryInterface
- //
- // Returns a pointer to the specified interface on a component to which a
- // client currently holds an interface pointer.
- //
- STDMETHODIMP
- CBaseEventServer::QueryInterface(REFIID inRefID, void** outObj)
- {
- ErrorCode result = CBaseCOM::QueryInterface(inRefID, outObj);
-
- if ( result == E_NOINTERFACE )
- {
- void* pv = nil;
-
- if (inRefID == IID_IConnectionPointContainer)
- {
- if ( mCPContainerP )
- return mCPContainerP->QueryInterface(IID_IConnectionPointContainer, outObj);
- }
-
- *outObj = pv;
-
- // if we got an interface, ref it and return ok
- if ( pv )
- {
- ((IUnknown*) pv)->AddRef();
- result = S_OK;
- }
- }
-
- return result;
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CBaseEventServer::AddOutGoingInterface
- //
- Boolean
- CBaseEventServer::AddOutGoingInterface(IID outgoingInterfaceID)
- {
- Boolean addedIt = false;
-
- // right now, we only support one outgoing interface.
- assert(mOutgoingInterfaceID == kUninitializedInterfaceID);
- mOutgoingInterfaceID = outgoingInterfaceID;
-
- addedIt = true;
-
- return addedIt;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CBaseEventServer::SetUpConnectionPoints
- //
- void
- CBaseEventServer::SetUpConnectionPoints(void)
- {
- // MMF: It seems to me that all of this is a bit dangerous to do in
- // a constructor the way the MS samples do, so we do it here. The
- // superclass can call it whenever it wants.
-
- if ( ! mCPContainerObj )
- {
- // Create the new connection point container object
- mCPContainerObj = new CCPContainer(NUM_EVENT_SERVER_CONNECTIONS);
-
- if ( mCPContainerObj )
- {
- // If we have a container object, allocate the connection points.
- // We currently only support one connection point.
- if ( mCPContainerObj->QueryInterface(IID_IConnectionPointContainer, &mCPContainerP) == S_OK
- && mCPContainerP )
- {
- mCPContainerObj->AddConnectionPoint(mOutgoingInterfaceID);
- }
- }
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CBaseEventServer::FireEvent
- //
-
- STDMETHODIMP
- CBaseEventServer::FireEvent(REFIID refID, long eventID, PlatformEvent * event)
- {
- if ( mCPContainerP )
- {
- IEnumConnectionPoints * enumCP;
- IEnumConnections * enumC;
- CONNECTDATA connectData;
- IUnknown * eventTarget;
- IConnectionPoint * connectionPoint;
-
- // Get an enumerator for the connection points
- if ( SUCCEEDED(mCPContainerP->EnumConnectionPoints(&enumCP)) )
- {
- // Loop through all the connection points for this control
- while ( enumCP->Next(1, &connectionPoint, nil) == NOERROR )
- {
- // Get all the connections for this connection point
- if ( SUCCEEDED( connectionPoint->EnumConnections(&enumC) ))
- {
- // Loop through all the connections for this connection point
- while ( enumC->Next(1, &connectData, nil) == NOERROR )
- {
- // Get the interface implementation for this connection
- // if successful, fire the event
- if ( SUCCEEDED( connectData.pUnk->QueryInterface(refID, (void**) &eventTarget) ))
- FireOneEvent(refID, eventID, eventTarget, event);
- }
-
- // Release the enumerator
- enumC->Release();
- }
- }
-
- enumCP->Release();
- }
- }
-
- return ResultFromScode(S_OK);
- }
-